package com.xiaoman.httpremote.base;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class HttpRemoteFactoryBean<T> implements FactoryBean<T> {
    private Class<T> type;
    public HttpRemoteFactoryBean(Class<T> type) {
        this.type = type;
    }
    @Override
    public T getObject() throws Exception {
        return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new HttpRemoteHandler<>(type));
    }

    @Override
    public Class<?> getObjectType() {
        return type;
    }
}
